define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shopro/withdrawgolden/index' + location.search,
                    // add_url: 'shopro/withdrawgolden/add',
                    // edit_url: 'shopro/withdrawgolden/edit',
                    // del_url: 'shopro/withdrawgolden/del',
                    // multi_url: 'shopro/withdrawgolden/multi',
                    // import_url: 'shopro/withdrawgolden/import',
                    table: 'shopro_withdraw_golden',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'amount', title: __('Amount'), operate:'BETWEEN'},
                        {field: 'charge_fee', title: __('Charge_fee'), operate:'BETWEEN'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'withdraw_sn', title: __('Withdraw_sn'), operate: 'LIKE'},
                        {field: 'paid_fee', title: __('实际到账'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'reason', title: __('拒绝原因'), operate: 'LIKE'},
                        {field: 'platform', title: __('Platform'), searchList: {"H5":__('Platform h5'),"WechatOfficialAccount":__('Platform wechatofficialaccount'),"WechatMiniProgram":__('Platform wechatminiprogram'),"App":__('Platform app')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('审核'),
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-success btn-xs btn-detail btn-dialog',
                                    url: 'shopro/withdrawgolden/edit',
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.status == 0) {
                                            return true;
                                        } else {
                                            return false;
                                        }
                                    },
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
